<?php
/**
 * error view class
 *
 * @author raphael seebacher <raphasee@ee.ethz.ch>
 * @version 0.01
 */
class error_view extends view {
    protected $error_message = '';
    protected $http_status = NULL;
    protected static $http_status_codes = Array(
      400 => 'Bad Request',
      401 => 'Unauthorized',
      404 => 'Not Found',
      500 => 'Internal Server Error',
    );
    
    final protected function set_status_code($status_code) {
        if (array_key_exists($status_code, self::$http_status_codes)) {
            $this->http_status = $status_code.' '
                .self::$http_status_codes[$status_code];
        }
    }

    public function __construct($error_message, $status_code) {
        $this->error_message = $error_message;
        $this->set_status_code($status_code);
    }

    public function send_header() {
        if ($this->http_status != NULL) {
            header('Status: '.$this->http_status);
        }
        header('Content-Type: text/plain');
    }

    public function get_content() {
        return $this->error_message;
    }
}
?>